<?php
class Admin_CountryguideController extends Zend_Controller_Action
{
    protected $_em;
    protected $_repo;
    public function init()
    {
    	$this->_em = Zend_Registry::get('doctrine');
    	$this->_flash = $this->_helper->getHelper('FlashMessenger');
    }
    
	/************** SPOTS *************/
	public function indexAction()
	{
	    $this->view->manager = 'MANAGEMENT SPOT LIST';
	    $id = $this->_getParam('id', 0);
	    $this->_repo = $this->_em->getRepository('\Entities\HaeSpot');
	    if ( $id != 0 )
	    {
	    	$this->_repo->deleteById($id);
	    }
	    $this->view->object = $this->_repo->findAll();
	}
	public function detailspotAction()
	{
	    $id = $this->_getParam('id', 0);
	     
	    $form = new Admin_Form_Spot();
	    $this->view->form = $form;
	    
	    if($id == 0 )
	    {
	    	$this->view->manager = 'ADD NEW SPOT';
	    	if($this->getRequest()->isPost())
	    	{
	    	    $this->_repo->saveAll($id,'spot',$this->getRequest()->getPost());
	    		$this->_helper->flashMessenger('Add successfully');
	    	}
	    }
	    else
	    {
	    	$this->_repo = $this->_em->getRepository('Entities\HaeSpot');
	    	
	    	if($this->getRequest()->isPost())
	    	{
	    	    $this->_repo->saveAll($id,'Spot',$this->getRequest()->getPost());
	    		$this->_helper->flashMessenger('Edit successfully');
	    	}
	    	
	    	$data = $this->_repo->findOneById($id);
	    	
	    	$this->view->manager = 'EDITOR  SPOT :'.$data->getTitleEn();
	    	$form->populate($data->toArray());
	    }
	}

	/************** PLACE INTEREST *************/
	public function interestAction()
	{
		
	}
	public function detailinterestAction()
	{
		
	}
	
	/************** RESTAURANT *************/
	public function restaurantAction()
	{
		
	}
	public function detailrestaurantAction()
	{
		
	}
	
	/************** SHOPPING *************/
	public function shoppingAction()
	{
		$this->view->manager = 'MANAGEMENT SHOPPING LIST';
	    $id = $this->_getParam('id', 0);
	    $this->_repo = $this->_em->getRepository('\Entities\HaeShopping');
	    if ( $id != 0 )
	    {
	    	$this->_repo->deleteById($id);
	    }
	    $this->view->object = $this->_repo->findAll();	
	}
	public function detailshoppingAction()
	{
	$id = $this->_getParam('id', 0);
	     
	    $form = new Admin_Form_Shopping();
	    $this->view->form = $form;
	    
	    if($id == 0 )
	    {
	    	$this->view->manager = 'ADD NEW SHOPPING';
	    	if($this->getRequest()->isPost())
	    	{
	    	    $this->_repo->saveAll($id,'Shopping',$this->getRequest()->getPost());
	    		$this->_helper->flashMessenger('Add successfully');
	    	}
	    }
	    else
	    {
	    	$this->_repo = $this->_em->getRepository('Entities\HaeShopping');
	    	
	    	if($this->getRequest()->isPost())
	    	{
	    	    $this->_repo->saveAll($id,'Shopping',$this->getRequest()->getPost());
	    		$this->_helper->flashMessenger('Edit successfully');
	    	}
	    	
	    	$data = $this->_repo->findOneById($id);
	    	
	    	$this->view->manager = 'EDITOR  SHOPPING :'.$data->getTitleEn();
	    	$form->populate($data->toArray());
	    }
	}
}
?>